package com.castbefore.mobile.android;

import android.accounts.Account;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;

public class ChooseGoogleAccountActivity extends Activity {
	private final int DIALOG_ACCOUNTS=1;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        showDialog(DIALOG_ACCOUNTS);
    }
    protected Dialog onCreateDialog(int id){
    	  switch (id) {
    	    case DIALOG_ACCOUNTS:
    	      AlertDialog.Builder builder = new AlertDialog.Builder(this);
    	      builder.setTitle("Select a Google account");
    	      GoogleAccountManager googleAccountManager = new GoogleAccountManager(this);
    	      Account[] accounts = googleAccountManager.getAccounts();
    	      final int size = accounts.length;
    	      String[] names = new String[size];
    	      for (int i = 0; i < size; i++) {
    	        names[i] = accounts[i].name;
    	      }
    	      builder.setItems(names, new DialogInterface.OnClickListener() {
    	        public void onClick(DialogInterface dialog, int which) {
    	          // Stuff to do when the account is selected by the user
    	          //gotAccount(accounts[[]which]);
    	        }
    	      });
    	      return builder.create();
    	  }
    	  return null;
    }
}